package no.group.gowther.service.dto.param;

import no.group.gowther.exception.BusinessException;
import no.group.gowther.exception.CannotResolveOnePieceTypeException;
import no.group.gowther.exception.ErrorMessage;
import no.group.gowther.util.OnePieceUtils;

import java.nio.file.Path;
import java.util.Collections;
import java.util.List;

public class OnePieceSaveDTO {
    private Path filePath;
    private String name;
    private List<Long> tagId;

    public OnePieceSaveDTO(Path filePath, String name, List<Long> tagId) {
        this.filePath = filePath;
        this.name = name;
        this.tagId = tagId;
        check();
    }

    private void check() {
        try {
            OnePieceUtils.resolveOnePieceType(filePath);
        } catch (CannotResolveOnePieceTypeException e) {
            throw BusinessException.createException(ErrorMessage.SYSTEM_ERROR.getErrorCode(), "无法解析文件[%s]类型".formatted(filePath));
        }
    }

    public Path getFilePath() {
        return filePath;
    }

    public void setFilePath(Path filePath) {
        this.filePath = filePath;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Long> getTagId() {
        return tagId;
    }

    public void setTagId(List<Long> tagId) {
        if (tagId == null) {
            this.tagId = Collections.emptyList();
            return;
        }
        this.tagId = tagId;
    }
}
